package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.PremisesApiService;
import com.yixun.qfbao.apidto.GetPremisesListByCompanyIdReqDto;
import com.yixun.qfbao.apidto.GetPremisesListByCompanyIdResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.GetPremisesListByCompanyIdReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author guifang.weng
 * @create 2017-12-14 11:04
 **/
@Service
public class GetPremisesListByCompanyIdHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetPremisesListByCompanyIdHander.class);

    @Autowired
    private PremisesApiService premisesApiService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<GetPremisesListByCompanyIdResDto> res = new BaseResponseDTO<>();
        GetPremisesListByCompanyIdResDto resDto = new GetPremisesListByCompanyIdResDto();
        GetPremisesListByCompanyIdReqVo reqVo = (GetPremisesListByCompanyIdReqVo) reqDto;
        GetPremisesListByCompanyIdReqDto getPremisesListByCompanyIdReqDto = reqVo.getParams();
        try {
            resDto = premisesApiService.getPremisesListByCompanyId(getPremisesListByCompanyIdReqDto);
        } catch (Exception e) {
            logger.error("GetPremisesListByCompanyIdHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg("获取数据失败");
        }
        res.setResult(resDto.getResult());
        res.setResData(resDto);
        return res;
    }
}
